using JT808Protocol.Common;
using System;
using System.Text.Json.Serialization;

namespace JT808Protocol.Models.BodyParserStrategy.Location.LocationAddition
{
    /// <summary>
    /// 超速报警附加信息消息体数据格式
    /// </summary>
    public class LaOverSpeed_0x11 : ILocationAddition
    {
        /// <summary>
        /// 0：无特定位置
        /// 1：圆形区域
        /// 2：矩形区域
        /// 3：多边形区域
        /// 4：路段
        /// </summary>
        [JsonPropertyName("位置类型")] public byte LocationType { get; set; }

        /// <summary>
        /// 编号
        /// </summary>
        [JsonPropertyName("编号")] public uint AreaOrLineSectionID { get; set; }

        public override ILocationAddition ReadEntity(ReadOnlySpan<byte> source, int startIndex)
        {
            DataLength = (byte)(source[startIndex + 1] + 2);
            if (DataLength < 2 + 1)
            {
                //Logger.Warn($"位置附加信息的超速报警信息长度错误，略过解析");
                return null;
            }

            LocationType = source[startIndex + 2];

            if (LocationType == 0)
            {
                return null;
            }
            if (DataLength != 5 + 2)
            {
                //Logger.Warn($"位置附加信息的超速报警信息长度错误，略过解析");
                return null;
            }

            //区域或路段ID
            AreaOrLineSectionID = ParseHelper.Uint32(ref source, startIndex + 3);

            return this;
        }
    }
}